package HomeWork.SocketP;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    private Socket socket;
    public Client(){
        try {

                System.out.println("Ready to find the server");
                socket =new Socket("localhost",8090);
                System.out.println("Connected");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try(OutputStream out=socket.getOutputStream()) {

            PrintWriter pw=new PrintWriter(out,true);
            Scanner sc=new Scanner(System.in);
            String s;
            while(true){
                s=sc.nextLine();
                if("exit".equals(s)){
                    break;
                }
                pw.println(s);

            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Client client=new Client();
        client.start();
    }
}
